<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>AngularJS&middot;Hello AngularJS</title>
    <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.2/css/bootstrap.css">
    <style>
        .demo{
            margin-bottom:10px;
        }
    </style>
</head>
<body>

 <div class="container">
     <div class="row">
         <nav class="navbar navbar-default navbar-static-top">
             <div class="container-fluid">
                 <div class="navbar-header">
                     <a class="navbar-brand" href="../index.html">首页</a>
                 </div>
                 <ul class="nav navbar-nav">
                    <li class="active"><a href="javascript:void(0)">Link</a></li>
                    <li><a href="javascript:void(0)">Link2</a></li>
                 </ul>
             </div>
         </nav>
     </div>
     <div class="row demo" ng-app="myModule">
         <h3>AngularJS IOC依赖注入示例</h3>
         <div ng-controller="MyController">
             <button ng-click="sayHello()">Hello</button>
         </div>
     </div>
 </div>
 </div>
</body>
</html>
<script src="http://cdn.bootcss.com/angular.js/1.3.8/angular.js" type="text/javascript"></script>
<script>
    var app=angular.module("MyAPP",[]);

    app.factory
    angular.module('myModule', []).factory('greeter', function($window) {
        return {
            greet: function(text) {
                $window.alert(text);
            }
        };
    });

    var injector = angular.injector('myModule');
    var greeter = injector.get('greeter');

    function MyController($scope, greeter) {
        $scope.sayHello = function() {
            greeter('Hello World');
        };
    }

    injector.instantiate(MyController);
</script>
